At 01:42 +0300 on 11/08/1999, Clayton Cottingham wrote:
> if we put in an index or not an explain say it still does a seq scan,
> same amount of time taken!
>
> ive tried putting the index using just the oid , a combo of some fields
> of our data using btree
>
> where/what rules should be followed for setting up a good indexing
> scheme under pg?
You should put indices on the fields mentioned in your query's WHERE clause.
You should try and avoid using functions on the fields in a WHERE clause.
For example, even if you have an index on the field "surname" in your
table, a query with WHERE upper( surname ) = "SMITH" will not use that
index. You can define indices on the function upper(surname) if this sort
of query is common.
The same goes for operators such as LIKE. LIKE will only use the index if
the expression is anchored to the beginning of the string, as in WHERE
surname LIKE 'Smi%', but not WHERE surname LIKE '%mit%'.
And always keep in mind that adding indices penalizes you on insert and update.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma